package com.yh.util;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.InputStream;

public class UserMapperTest {

    private Object MyBatisUtil;

    @Test
    public void testGetUserById() {
        // 加载MyBatis配置文件
        String resource = "mybatis-config.xml";
        InputStream inputStream = UserMapperTest.class.getClassLoader().getResourceAsStream(resource);
        // 创建SqlSessionFactory
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        // 创建SqlSession
        try (SqlSession session = sqlSessionFactory.openSession()) {
            // 获取Mapper接口的实现类对象
            UserMapper mapper = session.getMapper(UserMapper.class);
            // 调用Mapper方法
            MyBatisUtil user = mapper.getUserById(1);
            System.out.println(MyBatisUtil);
        }
    }
}
